package com.ycdx.zwzc.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.ycdx.zwzc.impl.ReasonImpl;
import com.ycdx.zwzc.pojo.Reason;

public class ReasonAction extends ActionSupport implements Preparable{
	
	private List<Reason> allReasons;
	private static final long serialVersionUID = -512728776868877795L;
	private String id;
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}


	private Reason reason;
	
	public Reason getReason() {
		return reason;
	}
	public void setReason(Reason reason) {
		this.reason = reason;
	}
	public List<Reason> getAllReasons() {
		return allReasons;
	}
	public void setAllReasons(List<Reason> allReasons) {
		this.allReasons = allReasons;
	}
	public String show(){
		return "success";
	}
	public String add(){
		return "success";
	}
	/**
	 * 添加故障原因
	 * @return
	 */
	public String addNew(){
		int flag = ReasonImpl.addReason(reason);
		//System.out.println(request.getEditor());
		if(flag==1){
			//添加成功
			addActionMessage("故障原因添加成功！");
			
		}else{
			//添加不成功
			addActionMessage("故障原因添加不成功，请重试！");
			
		}
		return "list";
	}
	
	public String edit(){
		//System.out.println(id);
		reason = ReasonImpl.getReasonById(id);
		return "success";
	}
	
	/**
	 * 故障原因修改
	 * @return
	 */
	public String update(){
		int flag = ReasonImpl.update(reason);
		//System.out.println(request.getEditor());
		if(flag==1){
			//添加成功
			addActionMessage("故障原因修改成功！");
			
		}else{
			//添加不成功
			addActionMessage("故障原因修改不成功，请重试！");
			
		}
		return "list";
	}
	
	public String delete(){
		//System.out.println(id);
		int flag = ReasonImpl.deleteReason(id);
		//System.out.println(flag);
		if(flag==1){
			//删除成功
			addActionMessage("故障原因删除成功！");
			
		}else{
			//添加不成功
			addActionMessage("故障原因删除不成功，请重试！");
			
		}
		return "list";
	}
	
	
	/**
	 * 初始化产品类型
	 */
	public void prepare() throws Exception {
		// TODO Auto-generated method stub
		allReasons = ReasonImpl.queryAllReasons();
	}
}
